package com.icarsaas.saas.tenant.cars.customer.web;

import com.icarsaas.saas.common.page.SoulPage;
import com.icarsaas.saas.common.utils.ResultVoUtil;
import com.icarsaas.saas.common.vo.ResultVo;
import com.icarsaas.saas.tenant.cars.customer.model.Member;
import com.icarsaas.saas.tenant.cars.customer.model.XmSelectModel;
import com.icarsaas.saas.tenant.cars.customer.service.MemberService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @title: MemberController
 * @description: 会籍卡管理
 * @author xrong120@gmail.com
 * @date 2021年1月23日
 */
@Controller @Api(tags="会籍模块") @RequestMapping(value = "/cars/member")
public class MemberController {
	@Autowired private MemberService memberService;
	
	@GetMapping("/memberList")
	public String memberList() {
		return "/customer/memberList";
	}

	@PostMapping("listSoulTable") @ResponseBody
	public Object listSoulTable(SoulPage<Map<String, Object>> page, @RequestBody Map<String, Object> params) {
		page.setParams(params, page);
//		page = memberService.listSoulData(page, params);
		return page;
	}

	/**
	 * 店铺列表，返回json方式提供给xm-select使用
	 */
	@GetMapping({"/listMember"}) @ResponseBody
	public ResultVo<?> listMember() {
		List<Member> list = memberService.findAll();
		List<XmSelectModel> models = new ArrayList<XmSelectModel>();
		XmSelectModel model = null;
		if (list != null && list.size() > 0) {
			for (Member member : list) {
				model = new XmSelectModel();
				model.setValue(member.getId());
				model.setName(member.getName());
				models.add(model);
			}
		}
		return ResultVoUtil.success(models);
	}

}
